package com.escom.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.escom.entidad.ArritmiaVO;
import com.escom.utils.Constantes;

/**
 * Created by Carlos on 7/04/14.
 */
public class ArritmiaDAO {

    private Context context;

    public ArritmiaDAO(Context context){
        this.context = context;
    }


    public void createMultipleArrimita(ArritmiaVO[] arrayArritmia){
        DataBaseManager dataBaseManager = new DataBaseManager(context);
        SQLiteDatabase sqLiteDatabase = dataBaseManager.getWritableDatabase();
        if (sqLiteDatabase != null) {
            for (int i = 0; i < arrayArritmia.length; i++) {
                ArritmiaVO arritmia = arrayArritmia[i];
                //Log.d("Logger PacienteDAO {}", paciente.toString());

                ContentValues contentValues = new ContentValues();
                try {
                    contentValues.put(DataBaseManager.ID_ARRITMIA, arritmia.getIdArritmia());
                    contentValues.put(DataBaseManager.TIPO_ARRITMIA, arritmia.getTipoArritmia());
                    sqLiteDatabase.insertOrThrow(DataBaseManager.HLC_ARRITIMIA_CAT, null, contentValues);
                } catch (android.database.sqlite.SQLiteConstraintException exSQL) {
                    Log.d(Constantes.LOG_ID, this.getClass().getName() + " Error administrado");
                    sqLiteDatabase.update(DataBaseManager.HLC_ARRITIMIA_CAT, contentValues,
                            DataBaseManager.ID_ARRITMIA + " = " + arritmia.getIdArritmia(), null);

                }
            }
        }
    }
}
